package com.six.work.mapper;

import com.six.work.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface InvitationMapper {
    @Select("SELECT invitation.*,applicant.applicant_name FROM invitation JOIN applicant applicant on invitation.applicant_id = applicant.applicant_id ORDER BY invitation.release_time DESC")
    List<InvView> findAllInvitation();

    @Select("SELECT * from invitation where post_id=#{post_id}")
    Invitation SelectInvByID(Integer post_id);

    @Select("SELECT applicant.applicant_name,invitation.* " +
            "FROM it.invitation JOIN it.applicant ON invitation.applicant_id=applicant.applicant_id " +
            "WHERE invitation.title LIKE '%${title}%' " +
            "ORDER BY post_id;")
    List<Invitation> findPostByTitle(String title);

    @Delete("DELETE from invitation where post_id=#{post_id}")
    Integer DelPostByID(Integer post_id);

    @Select("select * from invitation join applicant on invitation.applicant_id=applicant.applicant_id where post_id=#{post_id};")
    List<Invitation> findContent(Integer post_id);

    @Insert("insert into invitation (post_id,title,summarize,content,applicant_id,state,reasons) values(#{post_id},#{title},#{summarize},#{content},#{applicant_id},#{state},#{reasons})")
    Integer insertInvitation(Invitation invitation);   //增加

    @Update("update invitation set post_id=#{post_id},title=#{title},summarize=#{summarize},applicant_id=#{applicant_id},release_time=#{release_time},state=#{state},reasons=#{reasons},content=#{content} where post_id=#{post_id};")
    Integer updateInvitation(Invitation invitation);

}
